import axios from "axios"
import {baseUrl} from '../../public/api.js'
// axios.defaults.baseURL = baseUrl
const qs = require('qs')
const api= {
	async get(url,data){
		if(url.startsWith('/es/jsc')){
			// axios.defaults.baseURL = 'http://168.160.19.112:8004'
			axios.defaults.baseURL = 'http://47.96.145.185:8003'

		}else if(url.startsWith('/api/v1')){
			axios.defaults.baseURL = 'http://47.92.214.92:8081'
		}else{
			axios.defaults.baseURL = baseUrl
		}
		try{
			let res=await axios.get(url,{params:data})
			// console.log('---------', res)
			// let data = res.data
			return new Promise((resolve,reject)=>{
				// if(res.status===200){
					resolve(res)
				// }else{
				// 	reject(res)
				// }
			})
		}catch(err){
			console.log(axios.defaults.baseURL+' 接口服务器错误')
			console.log(err)
		}
	},
	async post(url,data){
		let res
		if(url.startsWith('/es/jsc')){
			// axios.defaults.baseURL = 'http://168.160.19.112:8004'
			axios.defaults.baseURL = 'http://47.96.145.185:8003'
		}else if(url.startsWith('/api/v1')){
			axios.defaults.baseURL = 'http://47.92.214.92:8081'
		}else{
			axios.defaults.baseURL = baseUrl
		}
		try{
			let res0 = await axios.post(url,data)	
			res = res0.data
			// console.log('==== ',res)
			return new Promise((resolve,reject)=>{
				if(res.status.code=='1'||res.status=='1'||res.status===200){
					resolve(res)
				}else{
					reject(res)
				}
			})
		}catch(err){
			console.log('接口服务器错误')
			console.log(err)
		}
	}
}
export  {api}